package com.smartHire.service.impl;

import com.smartHire.dao.AddressDao;
import com.smartHire.dao.UserDao;
import com.smartHire.domain.Address;
import com.smartHire.domain.User;
import com.smartHire.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource(name = "userDao")
    private UserDao userDao;
    @Resource(name = "addressDao")
    private AddressDao addressDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void setAddressDao(AddressDao addressDao) {
        this.addressDao = addressDao;
    }

    @Override
    public int addUser(User user) {
        try {
            int nums = userDao.insertUser(user);
            return nums;
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<User> queryUser() {
        try {
            List<User> users = userDao.selectUsers();
            return  users;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public User queryUserById(User user) {
        try {
            User user1= userDao.selectUserByID(user);
            return user1;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int updateBalance(User user) {
        try {
            int nums = userDao.updateBalance(user);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int addAddress(Address address) {
        try {
            int nums = addressDao.insertAddress(address);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<Address> queryAddressByU_Id(Address address) {
        try {
            List<Address> addresses = addressDao.selectAddressesByU_Id(address);
            return addresses;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Address queryAddressByAddressId(Address address) {
        try {
            Address addresses = addressDao.selectAddressByAddressId(address);
            return addresses;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int updateAddress(Address address) {
        try {
            int nums = addressDao.updateAddress(address);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int updateDefaultAddress(Address address) {
        try {
            int nums = addressDao.updateDefaultAddress(address);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int deleteAddress(Address address) {
        try {
            int nums = addressDao.deleteAddress(address);
            return nums;
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0;
    }
}
